package com.gexiaobao.pigeon.ui.adapter

import android.graphics.Paint
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.ext.RxTextTool
import com.gexiaobao.pigeon.app.model.bean.FlashSaleGoodsListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemFlashSaleGoodsBinding

/**
 * @Author      : hxw
 * @Date        : 2024/1/27 16:40
 * @Describe    :
 */
class FlashSaleGoodsAdapter(data: ArrayList<FlashSaleGoodsListResponse.ListBean>) :
    BaseQuickAdapter<FlashSaleGoodsListResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_flash_sale_goods, data) {

    private var price = ""

    override fun convert(holder: DataBindBaseViewHolder, item: FlashSaleGoodsListResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemFlashSaleGoodsBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val tvPrice = holder.getView<AppCompatTextView>(R.id.tvItemFlashSaleGoodsPrice)
        val ivItemHotSalesImage = holder.getView<AppCompatImageView>(R.id.ivItemHotSalesImage)
        val tvItemFlashSaleGoodsOriPrice = holder.getView<AppCompatTextView>(R.id.tvItemFlashSaleGoodsOriPrice)
        tvItemFlashSaleGoodsOriPrice.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
        if (item.state == 3) {//1-未开始2-进行中3-已结束
            price = item.originalPrice.toString()
            holder.setGone(R.id.tvItemFlashSaleGoodsOriPrice, true)
            holder.setText(R.id.tvItemFlashSaleGoodsBuyNow, context.getString(R.string.activity_market_shop_product_detail_buy_now))
            RxTextTool.getBuilder("")
                .append("¥")
                .append(price).setBold().setAppearance(70).setTextColor(ContextCompat.getColor(context, R.color.color_fe4542))
                .into(tvPrice)
        } else {
            price = item.salePrice.toString()
            holder.setGone(R.id.tvItemFlashSaleGoodsOriPrice, false)
            holder.setText(R.id.tvItemFlashSaleGoodsBuyNow, context.getString(R.string.Snap_up))
            RxTextTool.getBuilder("")
                .append("¥")
                .append(price).setBold().setAppearance(70).setTextColor(ContextCompat.getColor(context, R.color.color_fe4542))
                .into(tvPrice)
        }

        ImageLoaderManager.loadRoundImageOrEmpty(context, item.imagePath, ivItemHotSalesImage, 12, R.drawable.shop_product_def)
    }
}